package com.ruoyi.ws.facade;


import java.util.ArrayList;
import java.util.List;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.AdminClass;
import com.ruoyi.system.domain.UserClass;
import com.ruoyi.system.service.IAdminClassService;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.system.service.IUserClassService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import static com.ruoyi.common.core.domain.AjaxResult.error;
import static com.ruoyi.common.core.domain.AjaxResult.success;

/**
 * 路径规划显示配置规则REST服务：提供有关路径规划显示配置规则的接口
 *
 * @author roytrack
 * @date 2020-05-25 17:37:24
 */
@RestController
@RequestMapping(path = "services/teacher")
public class TeacherResource {

  /**
   * LOGGER
   */
  private static final Logger LOGGER = LoggerFactory.getLogger(TeacherResource.class);
  @Autowired
  private IAdminClassService adminClassService;
  @Autowired
  private ISysUserService userService;
  @Autowired
  private IUserClassService userClassService;

  @PostMapping("/getClassList")
  @ResponseBody
  public AjaxResult getClassList (Long teacherId) {
    try {
      List<AdminClass> adminClassList = new ArrayList<AdminClass>();
      //老师班级关系表
      UserClass userClass = new UserClass();
      userClass.setUserId(teacherId);
      List<UserClass> userClassList = userClassService.selectUserClassList(userClass);
      for (UserClass userClass1 : userClassList) {
        AdminClass adminClass = adminClassService.selectAdminClassById(userClass1.getClassId());
        if(null!=adminClass){
          adminClassList.add(adminClass);
        }
      }
      return success(adminClassList);
    } catch (Exception e) {
      LOGGER.error("获取老师所在班级集合失败",e);
      return error("获取老师所在班级集合失败");
    }
  }

}
